package com.itheima.stock.web;

import com.itheima.stock.pojo.domain.InnerMarketDomain;
import com.itheima.stock.pojo.domain.StockBlockDomain;
import com.itheima.stock.pojo.domain.StockUpdownDomain;
import com.itheima.stock.pojo.domain.Stock4EvrDayDomain;
import com.itheima.stock.pojo.entity.Stock4MinuteDomain;
import com.itheima.stock.pojo.vo.updowncount;
import com.itheima.stock.service.StockService;
import com.itheima.stock.vo.resp.PageResult;
import com.itheima.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

@RestController
@RequestMapping("/api/quot")
@Api(tags = "大盘指数")
public class StockController {
    @Autowired
    private StockService stockService;

    //其它省略.....
    /**
     * 获取国内最新大盘指数
     * @return
     */
    @GetMapping("/index/all")
    @ApiOperation("获取国内最新大盘指数")
    public R<List<InnerMarketDomain>> innerIndexAll() throws ExecutionException {

        return stockService.innerIndexAll();
    }
    /**
     *需求说明: 获取沪深两市板块最新数据，以交易总金额降序查询，取前10条数据
     * @return
     */
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> sectorAll(){
        return stockService.sectorAllLimit();
    }

    /**
     * 分页查询股票最新数据，并按照涨幅排序查询
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/stock/all")
    public R<PageResult<StockUpdownDomain>> getStockPageInfo(@RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
                                                             @RequestParam(name = "pageSize",required = false,defaultValue = "20") Integer pageSize){
        return stockService.getStockPageInfo(page,pageSize);
    }
    @GetMapping("/stock/increase")
    public R<List<StockUpdownDomain>> getincrease()
    {
      return   stockService.getincrease();
    }
    @GetMapping("/stock/updown/count")
    public R<List<updowncount>> getupdowncount()
    {
        return  stockService.getupdowncount();
    }
    /**
     * 将指定页的股票数据导出到excel表下
     * @param response
     * @param page  当前页
     * @param pageSize 每页大小
     */
    @GetMapping("/stock/export")
    public void stockExport(@Autowired HttpServletResponse response, Integer page, Integer pageSize){
        stockService.stockExport(response,page,pageSize);
    }

    /*


    * */
    @GetMapping("/stock/tradeAmt")
    public R<Map<String,List<updowncount>>> gettradeAmt()
    {
        return stockService.gettradeAmt();
    }
    /**
     * 查询当前时间下股票的涨跌幅度区间统计功能
     * 如果当前日期不在有效时间内，则以最近的一个股票交易时间作为查询点
     * @return
     */
    @GetMapping("/stock/updown")
    @ApiOperation("查询当前时间下股票的涨跌幅度区间统计功能")
    public R<Map> getStockUpDown(){
        return stockService.stockUpDownScopeCount();
    }


    @ApiOperation("查询当天开盘到当前的数据")
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> stockScreenTimeSharing(String code){
        return stockService.stockScreenTimeSharing(code);
    }

    /**
     * 查询近7天的日k线
     * @param stockCode
     * @return
     */

    @ApiOperation("查询近7天的日k线")
    @RequestMapping("/stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> getDayKLinData(@RequestParam("code") String stockCode){
        return stockService.stockCreenDkLine(stockCode);
    }
}
